<?php


namespace App\Controller\Cooperative;


use App\Annotation\OperationLog;
use App\Controller\AbstractController;
use App\Request\Cooperative\TaskTagSaveRequest;
use App\Service\Cooperative\TaskTagService;
use Hyperf\Di\Annotation\Inject;

class TaskTagController extends AbstractController
{

    /**
     * @Inject()
     * @var TaskTagService
     */
    protected $taskTagService;

    /**
     * @OperationLog(event="配置中心-标签列表",platform="cooperative")
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function index()
    {
        $index = $this->taskTagService->index();
        return $this->response->success($index);
    }

    /**
     * @OperationLog(event="配置中心-添加/修改标签",platform="cooperative")
     * @param $id
     * @param TaskTagSaveRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function save($id, TaskTagSaveRequest $request)
    {
        $validated = $request->validated();
        $tag = $this->taskTagService->save($id, $validated);
        return $this->response->success($tag);
    }

    /**
     * @OperationLog(event="配置中心-删除标签",platform="cooperative")
     * @param int $id
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function delete(int $id)
    {
        $this->taskTagService->delete($id);
        return $this->response->success();
    }
}